﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_module_user : System.Web.UI.UserControl
{
    UserBus userbus = new UserBus();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getUser();
        }
    }
    public void getUser()
    {
        DataTable dt = userbus.getAllUsers();
        DataTable list_user = new DataTable();
        list_user.Columns.Add("id");
        list_user.Columns.Add("name");
        list_user.Columns.Add("href");
        DataRow dr;
        foreach (DataRow r in dt.Rows)
        {
            dr = list_user.NewRow();
            dr["id"] = r["user_group_id"];
            dr["name"] = r["user_name"];
            dr["href"] = "~//admin//default.aspx?action=form_user&user_id=" + Convert.ToInt32(r["user_id"]);
            list_user.Rows.Add(dr);
        }

        listuser.DataSource = list_user;
        listuser.DataBind();
        if (list_user.Rows.Count == 0)
        {
            text_empty.Visible = true;
        }
    }

    protected void list_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int user_id = Convert.ToInt32(listuser.DataKeys[e.Item.ItemIndex]);
        userbus.deleteUserByID(user_id);
        getUser();

    }
}